package org.mte.sak.mail;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.activation.DataSource;

/**
 * MailDataSource.
 *
 * @author Marco Traversari
 * @version $Revision: 1.1 $ $Date: 2011-04-18 08:38:02 $
 *
 */
public class MailDataSource implements DataSource {

	/**
	 * DEFAULT_MIME_TYPE
	 */
	private final static String DEFAULT_MIME_TYPE = "application/octet";
	
	/**
	 * Contenuto dell'allegato
	 */
	private ByteArrayOutputStream baos = null;

	/**
	 * Mime Type
	 */
	private String type = DEFAULT_MIME_TYPE;

	/**
	 * MailDataSource
	 * @param baos
	 */
	public MailDataSource(ByteArrayOutputStream baos) {
		this.baos = baos;
	}

	/**
	 * MailDataSource
	 * @param baos
	 * @param type
	 */
	public MailDataSource(ByteArrayOutputStream baos, String type) {
		this.baos = baos;
		this.type = type;
	}

	/**
	 * getInputStream
	 * @return inputStream
	 */
	public InputStream getInputStream() {
		return new ByteArrayInputStream(baos.toByteArray());
	}

	/**
	 * getName
	 * @return name
	 */
	public String getName() {
		return "";
	}

	/**
	 * getOutputStream
	 * @return outputStream
	 * @throws IOException
	 */
	public OutputStream getOutputStream() throws IOException {
		throw new IOException("cannot do this");
	}

	/**
	 * getContentType
	 * @return type
	 */
	public String getContentType() {
		return type;
	}
}